var http = require("http");

var server = http.createServer();

server.on("request", function(req, resp) {
	
	// resp.write("hello nodeJs");
	// resp.end();
	
	// 上面的方法比较麻烦，推荐使用
	// resp.end("hello nodeJs");
	
	var url = req.url;
	if (url === "/index") {
		resp.end("index");
	} else if (url === "/login") {
		resp.end("login page");
	} else if (url === "/json") {
		var product = [
			{
				name: 'apple',
				price: 1999
			},
			{
				name: 'pineapple',
				price: 8888
			}
		];
		resp.end(JSON.stringify(product));
	} else {
		resp.end("404 Not Found");
	}
});

server.listen(3000, function() {
	console.log("https://localhost:3000/启动");
});